<?php
    include('./config.php');
    include('./request.php');
    $CurrentPage = $result->currentPage;
    $pageSize = $result->pageSize;
    $arr = array();
    try{
        $pdo = new PDO($dsn,$user,$pass);
        $sql = "select count(goods_id) as num from goods";
        $res = $pdo->prepare($sql);
        $res->execute();
        $rea = $res->fetchAll(PDO::FETCH_ASSOC);
        $pageCount = ceil($rea['num']/$pageSize);
        $sql = "select * from goods limit ".(($CurrentPage-1)*$pageSize).",".$pageSize.";";
        $res = $pdo->prepare($sql);
        $res->execute();
        while($rs = $res->fetch(PDO::FETCH_ASSOC)){
            $arr2 = array('goods_id'=>$rs['goods_id'],'goods_name'=>$rs['goods_name'],'goods_price'=>$rs['goods_price'],'goods_type'=>$rs['goods_type'],'market_name'=>$rs['market_name'],'url'=>$rs['imgpath'],'pageCount'=>$pageCount);
            array_unshift($arr,$arr2);
        }
        echo json_encode($arr);
    }catch(PDOException $e){
        echo "error";
    }
?>